﻿using MaxStoreErp.Core.Exceptions;
using MaxStoreShop.Domain.Directories;
using MaxStoreShop.Logic.Services.Directories;
using MaxStoreShop.Logic.ServicesContracts.Directories;
using MaxStoreShop.Logic.Tests.FakeRepositories;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MaxStoreShop.Logic.Tests
{
    [TestClass]
    public class CharacterServiceTests
    {
        [TestMethod]
        public void DeleteCharacterShouldNormal()
        {
            CreateInstance().DeleteCharacter(new Character { Id = 1 });
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void DeleteCharacterShouldThrowErpRuntimeExceptionIfCharacterIsNull()
        {
            CreateInstance().DeleteCharacter(null);
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void DeleteCharacterShouldThrowErpRuntimeExceptionIfCharacterIsDebtor()
        {
            CreateInstance().DeleteCharacter(new Character { Id = 2 });
        }

        [TestMethod]
        public void SaveCharacterShouldNormal()
        {
            CreateInstance().SaveCharacter(new Character { FirstName = "Ivan", LastName = "Ivanov", Phone = "123" });
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void SaveCharacterShouldThrowErpRuntimeExceptionIfCharacterIsNull()
        {
            CreateInstance().SaveCharacter(null);
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void SaveCharacterShouldThrowErpRuntimeExceptionIfFirstNameIsNullOrEmpty()
        {
            CreateInstance().SaveCharacter(new Character { LastName = "Ivanov", Phone = "123" });
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void SaveCharacterShouldThrowErpRuntimeExceptionIfLastNameIsNullOrEmpty()
        {
            CreateInstance().SaveCharacter(new Character { FirstName = "Ivan", Phone = "123" });
        }

        [TestMethod]
        [ExpectedException(typeof(ErpRuntimeException))]
        public void SaveCharacterShouldThrowErpRuntimeExceptionIfPhoneIsNullOrEmpty()
        {
            CreateInstance().SaveCharacter(new Character { FirstName = "Ivan", LastName = "Ivanov" });
        }

        static ICharacterService CreateInstance()
        {
            return new CharacterService(new CharacterRepositoryFake());
        }
    }
}
